/**
 * @author： sce
 * @date：17-11-11
 */

!(function (global, _) {
    var GenerateToolBar = function (data) {
        this.data = {};
        this.htmlTmp = "<a href='javascript:void(0)' class='easyui-linkbutton' id='${id}' iconCls='${icon}' plain='true' onClick='${functionname}()'>${text}</a>";
    };

    var RECEIPT_TOOLBAR = {
        FRONT: Math.pow(2, 0),
        NEXT: Math.pow(2, 1),
        ADD: Math.pow(2, 2),
        SAVE: Math.pow(2, 3),
        DELETE: Math.pow(2, 4),
        VERIFY: Math.pow(2, 5),
        UNVERIFY: Math.pow(2, 6),
        SEARCH: Math.pow(2, 7),
        PRINT: Math.pow(2, 8),
        CHARGE: Math.pow(2, 9),
        EXPORT: Math.pow(2, 10),
        SEARCHALL: Math.pow(2, 11),
    };

    var TOOLBARDATA = [{
        "icon": "icon-left",
        "id": "btn_front",
        "text": "上张",
        "functionname": "front"
    }, {
        "icon": "icon-right",
        "id": "btn_next",
        "text": "下张",
        "functionname": "next"
    }, {
        "icon": "icon-add",
        "id": "btn_new",
        "text": "新建单据",
        "functionname": "new"
    }, {
        "icon": "icon-save",
        "id": "btn_save",
        "text": "保存单据",
        "functionname": "save"
    }, {
        "icon": "icon-remove",
        "id": "btn_remove",
        "text": "删除单据",
        "functionname": "remove"
    }, {
        "icon": "icon-to_do",
        "id": "btn_verify",
        "text": "审核单据",
        "functionname": "verify"
    }, {
        "icon": "icon-redo",
        "id": "btn_unverify",
        "text": "弃审单据",
        "functionname": "unverify"
    }, {
        "icon": "icon-search",
        "id": "btn_search",
        "text": "查询",
        "functionname": "search"
    }, {
        "icon": "icon-print",
        "id": "btn_print",
        "text": "打印单据",
        "functionname": "print"
    }, {
        "icon": "icon-usermanagement",
        "id": "btn_fee",
        "text": "收费",
        "functionname": "fee"
    }, {
        "icon": "icon-save",
        "id": "btn_load",
        "text": "导出",
        "functionname": "load"
    }, {
        "icon": "icon-undo",
        "id": "btn_undo",
        "text": "查看所有数据",
        "functionname": "undo"
    }];
    _.extend(GenerateToolBar, global.GenerateTemplate);

    GenerateToolBar.prototype.getToolBarContent = function (type, newdata) {
        var temp = 0,s;
        if(type instanceof Array){
            for(var i = 0, len = type.length; i < len; i++){
                if(type[i] in RECEIPT_TOOLBAR){
                    temp += RECEIPT_TOOLBAR[type[i]];
                }
            }
        }else if(!isNaN(type)){
            temp = type;
        }
        var tempData = [];
        for(var j = 0, lens = TOOLBARDATA.length; j < lens; j++) {
            s = temp & (1 << j);
            if(s !== 0) {
                tempData.push(TOOLBARDATA[j]);
            }
        }
        if(newdata){
            this.dataTmp = tempData.concat(newdata);
        }else{
            this.dataTmp = tempData;
        }
        return this.generate();
    };

    global.GenerateToolBar = GenerateToolBar;
})(typeof window !== "undefined" ? window : this, common);